package com.godz.frontData.index2;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.godz.mapper.index2SecretMapper;
import com.godz.pojo.index2Secret;
import org.springframework.web.bind.annotation.*;
import java.util.List;

//我的秘密
@RestController
public class secretData {
    final
    index2SecretMapper secretMapper;

    public secretData(index2SecretMapper secretMapper) {
        this.secretMapper = secretMapper;
    }

    //全部的先显示了
    @GetMapping("/index2/get/index2Secret")
    public List<index2Secret> getSecret(){
        return secretMapper.queryAllSecret();
    }
    //查询单个
    @GetMapping("/index2/get/index2Secret/{intId}")
    public index2Secret getOneSecret(@PathVariable("intId") Integer integer) {
        return secretMapper.selectOne(
                new QueryWrapper<index2Secret>().eq("id", integer)
        );
    }
    //增加一条
    @PostMapping("/index2/post/addSecret")
    public String addSecret(@RequestBody index2Secret secret) {
        secretMapper.insert(secret);
        return "insert OK";
    }
    //修改一条
    @PostMapping("/index2/post/editSecret")
    public String editSecret(@RequestBody index2Secret secret) {
        QueryWrapper<index2Secret> wrapper = new QueryWrapper<>();
        wrapper.eq("id", secret.getId());

        index2Secret secret1 = new index2Secret();

        secret1.setSecretTitle(secret.getSecretTitle());
        secret1.setSecretNumber(secret.getSecretNumber());
        secret1.setSecretCon(secret.getSecretCon());

        secretMapper.update(secret1, wrapper);
        return "Update OK";
    }
    //删除一条
    @GetMapping("/index2/get/deleteSecret/{id}")
    public String deleteSecret(@PathVariable("id") Integer integer) {
        secretMapper.deleteById(integer);
        return "Delete Ok";
    }
}
